var e = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/helpers/typeof")),
  base = require("../../base.js"),
  o = getApp();

Component({
  properties: {
    item: {
      type: Object,
      value: {},
      observer: function (e, t) {
        this._myPropertyChange(e, t);
      }
    }
  },
  data: {
    banner: base.IMGPATH + "bdd.png",
    play: base.IMGPATH + "play.png",
    checkedIndex: "",
    selectIndex: 0,
    showResult: !1,
    isAdShow: !0,
    btnText: "查看结果"
  },
  attached: function () {
    var e = this.data.item,
      t = 0;
    e && "number" == typeof e.selected && (t = e.selected), e.selected = t, this.setData({
      selectIndex: t,
      item: e
    });
  },
  methods: {
    checkHandle: function (e) {
      var t = e.currentTarget.dataset.index,
        s = this.data.item,
        n = this.data.selectIndex,
        o = s.questionType;
      this.setData({
        checkedIndex: t
      });
      var i = {
        index: t
      };
      if ("number" == typeof s.selected && (i.order = n), "SCORE" == o) n == s.crossHeadList.length - 1 && this.setData({
        showResult: !0
      });
      else if ("REDIRECT" == o) {
        s.crossHeadList[n].questionOptList[t].redirectSerialNum ? this.setData({
          showResult: !1
        }) : this.setData({
          showResult: !0
        });
      } else this.setData({
        showResult: !0
      });
      this.triggerEvent("changeIndex", i);
    },
    jumpPrev: function () {
      var e = this.data.item,
        t = e.questionType,
        s = this.data.selectIndex;
      "REDIRECT" == t ? (s = e.crossHeadList[s].prevNumber, this.triggerEvent("changeIndex", {
        index: e.crossHeadList[s].checked,
        prevStatus: !0,
        order: s
      })) : --s >= 0 && this.triggerEvent("changeIndex", {
        index: e.crossHeadList[s].checked,
        prevStatus: !0,
        order: s
      });
    },
    jumpToAnswer: function () {
      var e = this.data,
        t = e.item;
      e.isAdShow;
      wx.setStorageSync("questionAnswer", t), wx.redirectTo({
        url: "/pages/answer/index"
      });
    },
    playAd: function (e) {
      var t = null;
      wx.createRewardedVideoAd && ((t = wx.createRewardedVideoAd({
        adUnitId: "adunit-a3e93e13e60bcc44"
      })).onError(function (t) {
        e && e(), console.log("videoAd onError", t);
      }), t.onLoad(function (e) {
        console.log("videoAd onLoad", e);
      }), t.onClose(function (t) {
        (t && t.isEnded || void 0 === t) && e && e(), console.log("videoAd onClose", t);
      }), t.load().then(function () {
        console.log("激励视频加载成功"), t.show().then(function () {
          console.log("激励视频 广告显示成功");
        }).catch(function (t) {
          e && e(), console.log("激励视频 广告显示失败");
        });
      }).catch(function (e) {
        console.log("激励视频加载失败");
      }));
    },
    _myPropertyChange: function (t, s) {
      var n = this;
      t && "number" == typeof t.selected && ((0, e.default)(t.crossHeadList[t.selected].checked) || console.log("还未选择答案"),
        setTimeout(function () {
          n.setData({
            selectIndex: t.selected
          });
        }, 300));
    }
  }
});